<template>
  <div class="flex" v-if="mode === 'inline'">
    <div v-for="(item, index) in list" :key="item.key">
      <span>{{ item.title }}:</span>
      <span>{{ item.render ? item.render(data[item.dataIndex], data) : data[item.dataIndex] || '--' }}</span>
      <ga-divider direction="vertical" :style="dividerStyle" v-if="index < list.length - 1"></ga-divider>
    </div>
  </div>
  <div class="flex" v-else>
    <div v-for="(item, index) in list" class="card" :key="item.key" :style="item.style || {}">
      <div class="card-title" :title="item.title">{{ item.title }}:</div>
      <div class="card-value">{{ item.render ? item.render(data[item.dataIndex], data) : data[item.dataIndex] || '--' }}
      </div>

    </div>
  </div>
</template>

<script setup>
const dividerStyle = {
  height: '14px',
  margin: '0 20px'
}
const props = defineProps({
  list: {
    type: Array,
    default: () => ([])
  },
  data: {
    type: Array,
    default: () => ([])
  },
  mode: {
    type: String,
    default: 'inline'
  }
})
</script>

<style scoped lang="scss">
.card {
  background-color: rgba(34, 110, 231, 0.06);
  padding: 12px;
  border-radius: 4px;
  flex-basis: 0;
  flex-grow: 1;
  margin: 0 4px;
  overflow: hidden;

  .card-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .card-value {
    font-size: 18px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.85);
  }

  &:first-child {
    margin-left: 0;
  }

  &:last-child {
    margin-right: 0;
  }
}
</style>
